//*****************************************************************************
// JFab (http://code.google.com/p/jfab)
// Copyright (c) 2011-2012 JFab.org
// Admin jfab@jeffreythompson.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package org.jfab.swingui.decorator;

import org.apache.commons.lang3.Validate;
import org.jfab.core.model.CGClass;
import org.jfab.core.model.CGConstructor;
import org.jfab.core.model.CGEnum;
import org.jfab.core.model.CGEnumItem;
import org.jfab.core.model.CGField;
import org.jfab.core.model.CGInitializationBlock;
import org.jfab.core.model.CGInterface;
import org.jfab.core.model.CGMethod;
import org.jfab.core.model.CGMethodDeclaration;
import org.jfab.core.model.CGParameter;
import org.jfab.core.model.CGProperty;
import org.jfab.core.model.CGSpec;
import org.jfab.swingui.IconManager;

/**
 * Provides a factory for <code>Decorator</code> objects.
 */
public class DecoratorFactory
{
    /**
     * @param component Component. (required)
     * @param parent Parent.
     * @param iconManager Icon manager. (required)
     * 
     * @return a new decorator for the given parameter.
     */
    public Decorator<?> create(final Object component,
            final Decorator<?> parent, final IconManager iconManager)
    {
        Validate.notNull(component, "component is null");

        Decorator<?> answer;

        if (component instanceof CGSpec)
        {
            answer = new CGSpecDecorator((CGSpec)component, iconManager);
        }
        else if (component instanceof CGClass)
        {
            answer = new CGClassDecorator((CGClass)component, parent,
                    iconManager);
        }
        else if (component instanceof CGConstructor)
        {
            answer = new CGConstructorDecorator((CGConstructor)component,
                    parent, iconManager);
        }
        else if (component instanceof CGEnum)
        {
            answer = new CGEnumDecorator((CGEnum)component, parent, iconManager);
        }
        else if (component instanceof CGEnumItem)
        {
            answer = new CGEnumItemDecorator((CGEnumItem)component, parent,
                    iconManager);
        }
        else if (component instanceof CGField)
        {
            answer = new CGFieldDecorator((CGField)component, parent,
                    iconManager);
        }
        else if (component instanceof CGInitializationBlock)
        {
            answer = new CGInitializationBlockDecorator(
                    (CGInitializationBlock)component, parent, iconManager);
        }
        else if (component instanceof CGInterface)
        {
            answer = new CGInterfaceDecorator((CGInterface)component, parent,
                    iconManager);
        }
        else if (component instanceof CGMethod)
        {
            answer = new CGMethodDecorator((CGMethod)component, parent,
                    iconManager);
        }
        else if (component instanceof CGMethodDeclaration)
        {
            answer = new CGMethodDeclarationDecorator<CGMethodDeclaration>(
                    (CGMethodDeclaration)component, parent, iconManager);
        }
        else if (component instanceof CGParameter)
        {
            answer = new CGParameterDecorator((CGParameter)component, parent,
                    iconManager);
        }
        else if (component instanceof CGProperty)
        {
            answer = new CGPropertyDecorator((CGProperty)component, parent,
                    iconManager);
        }
        else
        {
            answer = null;

            System.err.println("create() Error: Unrecognized component type: "
                    + component + " " + component.getClass().getName());
        }

        return answer;
    }
}
